package com.example.project.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.project.R;
import com.example.project.bean.NaviBean;

import java.util.ArrayList;
import java.util.List;


public class RlvMainAdapter extends RecyclerView.Adapter {
    private ArrayList<NaviBean.DataBean> mList;

    public RlvMainAdapter(ArrayList<NaviBean.DataBean> list) {
        mList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
        return new VH(inflate);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        VH vh = (VH) viewHolder;
        vh.mTv.setText(mList.get(i).getName());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void addData(List<NaviBean.DataBean> data) {
        if (data != null && data.size() > 0) {
            mList.addAll(data);
            notifyDataSetChanged();
        }
    }


    class VH extends RecyclerView.ViewHolder{
        TextView mTv;

        public VH(View itemView) {
            super(itemView);

            this.mTv = (TextView) itemView.findViewById(R.id.tv);
        }
    }

















/*
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //nflate(R.layout.item, parent,如果不加parent 水平方向不会撑满
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
        return new VH(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        VH vh = (VH) holder;
        vh.mTv.setText(mList.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void addData(List<NaviBean.DataBean> data) {
        if (data != null && data.size()>0){
            mList.addAll(data);
            notifyDataSetChanged();
        }
    }

    class VH extends RecyclerView.ViewHolder{
        @BindView(R.id.tv)
        TextView mTv;
        public VH(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);

        }
    }*/
}
